﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pibby.Core.Web
{
	public static class UriBuilder
	{
		public static Uri Create(string candidateUri)
		{
			Uri created = null;

			try
			{
				created = new Uri(candidateUri);
			}
			catch (UriFormatException)
			{
				// try adjusting the link to make sense to Uri
				if (!candidateUri.StartsWith("http://"))
					candidateUri = "http://" + candidateUri;

				try
				{
					created = new Uri(candidateUri);
				}
				catch (UriFormatException)
				{
					// can't do anything else...
					throw;
				}
			}

			return created;
		}
	}
}
